﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Automation.Peers;
using System.Diagnostics.Contracts;
using System.Windows.Automation.Provider;

namespace UnitTestUtils.UI.Automation
{
    /// <summary>
    /// UIAutomation extensions for WPF Button control.
    /// </summary>
    public static class ButtonExtensions
    {
        /// <summary>
        /// Returns the IInvokeProvider interface for the button.
        /// </summary>
        /// <param name="button"></param>
        /// <returns>the interface if it is implemented</returns>
        public static IInvokeProvider GetInvokeInterface(this Button button)
        {
            Contract.Requires<ArgumentNullException>(button != null, "button");

            var peer = UIElementAutomationPeer.CreatePeerForElement(button);
            return (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);
        }

    }
}
